package cn.stu.cms.controller;

import cn.stu.cms.dto.NegotiationPageDto;
import cn.stu.cms.dto.PageDto;
import cn.stu.cms.pojo.Negotiation;
import cn.stu.cms.service.NegotiationService;
import cn.stu.cms.util.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * (Negotiation)表控制层
 *
 * @author gh
 * @since 2023-07-21 16:09:55
 */
@RestController
@RequestMapping("/negotiation")
@AllArgsConstructor
public class NegotiationController {

    private final NegotiationService negotiationService;


    /**
     * 查询全部对象
     *
     * @return 全部数据
     */
    @GetMapping("/page")
    public R<Page<Negotiation>> page(PageDto<Negotiation> page, NegotiationPageDto dto) {
        return negotiationService.getPage(page, dto);
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public R<Negotiation> queryById(@PathVariable Long id) {
        return R.ok(negotiationService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param negotiation 实体
     * @return 新增结果
     */
    @PostMapping("/save")
    public R<String> add(@RequestBody @Valid Negotiation negotiation) {
        return negotiationService.insert(negotiation);
    }

    /**
     * 编辑数据
     *
     * @param negotiation 实体
     * @return 编辑结果
     */
    public R<String> edit(@RequestBody @Valid Negotiation negotiation) {
        return R.ok();
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping("/delete/{id}")
    public R<String> deleteById(@PathVariable Long id) {
        return negotiationService.deleteById(id);
    }
}

